<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>IntersectionObserver 使用</title>
    <style>
      .container {
        background-color: red;
        width: 300px;
        height: 300px;
        display: flex;
        justify-content: center;
        align-items: center;
        margin-bottom: 10px;
        /* transition: all .5s; */
      }
      .item {
        height: 300px;
      }
    </style>
  </head>
  <body>
    <h1>通过 IntersectionObserver 监听元素是否已经出现在视图</h1>
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
    <div class="container" id="div">
      1
    </div>
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>

  </body>
  <script>
    const $div = document.querySelector('#div')

    const o = new IntersectionObserver((a) => {
      console.log(a)
    })
    
    o.observe($div)
  </script>
</html>
